package o2sjsc.activity;

import java.util.ArrayList;

import android.annotation.SuppressLint;
import android.app.ActionBar;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView;

@SuppressLint("NewApi")
public class CactegoryActivity extends Activity implements OnItemClickListener, OnClickListener{

	ListView listView;
	Button btnBack;

	/*
	 * (non-Javadoc)
	 * 
	 * @see android.app.Activity#onCreate(android.os.Bundle)
	 */
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_category);
		
		ActionBar actionBar = getActionBar();
		actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
		actionBar.setCustomView(R.layout.activity_category_action_bar);
		
		btnBack = (Button)findViewById(R.id.btnCateBack);
		btnBack.setOnClickListener(this);

		listView = (ListView) findViewById(R.id.listCategory);
		
		ArrayList<String> arr = new ArrayList<String>();
		arr.add(ValueConstants.HOME);
		arr.add(ValueConstants.BUSINESS);
		arr.add(ValueConstants.TECHCOLOY);
		arr.add(ValueConstants.MOBILE);
		arr.add(ValueConstants.SCIENCE);
		arr.add(ValueConstants.SCURITY);
		arr.add(ValueConstants.IT);
		arr.add(ValueConstants.INTERNET);
		arr.add(ValueConstants.COMPUTER);
		arr.add(ValueConstants.RECRUITMENT);
		final ViewMoreAdapter adapter = new ViewMoreAdapter(this, arr);
		
		listView.setAdapter(adapter);
		listView.setOnItemClickListener(this);
		
	}

	@Override
	public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
		TextView tvCateName = (TextView) view
				.findViewById(R.id.cateName);
		String cateName = tvCateName.getText().toString();
		setResult(RESULT_OK, (new Intent()).setAction(cateName));
		finish();
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.btnCateBack:
			super.onBackPressed();
			break;

		default:
			break;
		}
	}
}
